package com.it.gmall.task.schedule;

import com.it.gmall.mq.consts.MqConst;
import com.it.gmall.mq.service.SendMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

// 定时任务
@Component
public class ScheduledTask {
    @Autowired
    private SendMsgService sendMsgService;
    /*
    * 在每天得半夜十二点将商品放入redis中
    * 由于是测试 此处是每五秒执行一次
    * */
    // @Scheduled(cron = "0 0 0 1/1 * ? *")
    @Scheduled(cron = "0/5 * * * * ?")
    public void scheduleAddGoods(){
        System.out.println(new Date());
        // 发送消息给秒杀微服务
        // 如果秒杀的商品太多 将商品排队压入缓存 防止定时器并发
        sendMsgService.sendMsg(MqConst.EXCHANGE_DIRECT_TASK,MqConst.ROUTING_TASK_1,"");
    }
}
